import { http } from "@/utils/http";

export type UserResult = {
  code: number;
  message: string;
  result: {
    /** 用户名 */
    username: string;
    /** 当前登陆用户的角色 */
    roles: Array<string>;
    /** `token` */
    token: string;
    /** 用于调用刷新`accessToken`的接口时所需的`token` */
    refresh_token: string;
    /** `accessToken`的过期时间 */
    token_expire: number;
  };
};

export type RefreshTokenResult = {
  success: boolean;
  result: {
    /** `token` */
    accessToken: string;
    /** 用于调用刷新`accessToken`的接口时所需的`token` */
    refreshToken: string;
    /** `accessToken`的过期时间 */
    expires: number;
  };
};

/** 登录 */
export const getLogin = (data: object) => {
  return http.request<UserResult>("post", "/api/login", { data });
};

/** 刷新token */
export const refreshTokenApi = (data?: object) => {
  return http.request<any>("post", "/api/refresh_token", { data });
};
